package org.jsola.hr.helper;

import org.jsola.hr.dto.ErrorInfoAddDTO;
import org.jsola.hr.dto.ErrorInfoUpdateDTO;
import org.jsola.hr.entity.ErrorInfoDO;
import org.jsola.hr.query.ErrorInfoQuery;
import org.jsola.hr.service.IErrorInfoService;
import org.jsola.hr.vo.ErrorInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 异常记录表
 *
 * @author zhr
 */
@Component
public class ErrorInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private IErrorInfoService errorInfoService;

    /**
     * 生成add测试数据
     * @return ErrorInfoAddDTO
     */
    public ErrorInfoAddDTO getErrorInfoAddDTO(){
        ErrorInfoAddDTO errorInfoAddDTO = new ErrorInfoAddDTO();
        errorInfoAddDTO.setDeviecType(getRandomValue("varchar",32));
        errorInfoAddDTO.setErrorInfo(getRandomValue("text",2147483647));
        errorInfoAddDTO.setRemark(getRandomValue("varchar",32));
        return errorInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ErrorInfoUpdateDTO
     */
    public ErrorInfoUpdateDTO getErrorInfoUpdateDTO(ErrorInfoVO errorInfoVO){
        return errorInfoService.selectDOById(errorInfoVO.getId(), SITE_ID).to(ErrorInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ErrorInfoQuery
     */
    public ErrorInfoQuery getErrorInfoQuery() {
        ErrorInfoQuery errorInfoQuery = new ErrorInfoQuery();
        List<ErrorInfoDO> errorInfoDOList = errorInfoService.list(new ErrorInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(errorInfoDOList)) {
            ErrorInfoDO errorInfoDO = errorInfoDOList.get(0);
            errorInfoQuery = errorInfoDO.to(ErrorInfoQuery.class);
        }
        return errorInfoQuery;
    }

    /**
     * 保存示例
     * @return ErrorInfoVO
     */
    public ErrorInfoVO saveErrorInfoExample(){
        ErrorInfoAddDTO addDTO = this.getErrorInfoAddDTO();
        ErrorInfoVO errorInfoVO = errorInfoService.save(addDTO,buildTokenUser());
        return errorInfoVO;
    }


}

